package com.atguigu.guli.service.base.exception;

import com.atguigu.guli.common.base.result.ResultCodeEnum;
import lombok.Data;

/**
 * @className: GuliException
 * @description: 自定义异常
 * @date: 2020/11/28
 * @author: cakin
 */
@Data
public class GuliException extends RuntimeException {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 功能描述：构造器
     *
     * @author cakin
     * @date 2020/11/28
     * @param message 消息
     * @param code 状态码
     */
    public GuliException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 功能描述：构造器
     *
     * @author cakin
     * @date 2020/11/28
     * @param resultCodeEnum 结果枚举
     */
    public GuliException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    /**
     * 功能描述：打印完整的异常信息
     *
     * @author cakin
     * @date 2020/11/28
     * @return 打印结果
     */
    @Override
    public String toString() {
        return "GuliException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
